package org.yang.common.utils.http;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import java.util.Map;

/**
 * HttpServletRequest 工具类
 * @author: lslands
 * @version: 1.0
 * @create: 2024/5/12
 * @description:
 */
public class RequestUtils  {

    /**
     * 获取请求参数
     * @param request 入参
     * @return MultiValueMap<String,String>
     * @author lslands
     * @date 2024/5/12 16:31
     */
    public static MultiValueMap<String, String> getParameters(HttpServletRequest request) {
        Map<String, String[]> parameterMap = request.getParameterMap();
        MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>(parameterMap.size());
        parameterMap.forEach((key, values) -> {
            if (values.length > 0) {
                for (String value : values) {
                    parameters.add(key, value);
                }
            }
        });
        return parameters;
    }


}
